/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package presenter;

import view.Tela;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Iterator;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JFrame;
import javax.swing.text.BadLocationException;
import model.AnalisadorLexico;
import model.TabelaSimbolo;

/**
 *
 * @author Dikson
 */
public class PresenterView {

    Tela tela;
    AnalisadorLexico analisador;

    public PresenterView(Tela tela) {

        tela.setVisible(true);

        tela.getBtnAnaliseLexica().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                TabelaSimbolo tb = new TabelaSimbolo();
                AnalisadorLexico lexico = new AnalisadorLexico();
                int qteLinhas = tela.getTextArea().getLineCount();

                for (int i = 0; i < qteLinhas; i++) {

                    try {
                        int inicio = tela.getTextArea().getLineStartOffset(i);
                        int fim = tela.getTextArea().getLineEndOffset(i);
                        String linha = tela.getTextArea().getText(inicio, fim - inicio);
                        lexico = new AnalisadorLexico(linha, i + 1);
                        lexico.analisaCodigo();
                    } catch (BadLocationException ex) {
                        Logger.getLogger(PresenterView.class.getName()).log(Level.SEVERE, null, ex);
                    }
                }
                tb.analisa(lexico.getLexema());
            }
        });
    }
}
